/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2025-02-21 09:12:10
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-24 11:35:25
 * @FilePath: /vue3-admin-server/src/entities/converters/bitToBooleanConverter.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import type { ValueTransformer } from 'typeorm';

export const BitToBooleanConverter: ValueTransformer = {
    to: (value: boolean) => (value ? 1 : 0), // 将布尔值转换为 bit(1)
    from: (value?: Buffer) => {
        if (value) {
            return value.readUInt8(0) === 1; // 将 bit(1) 转换为布尔值
        }
        return false;
    }
};
